package com.keon.jianbao.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.keon.jianbao.R;
import com.keon.jianbao.base.SimpleAdapter;
import com.keon.jianbao.bean.Comment;
import com.keon.jianbao.ui.widget.CircleImageView;
import com.keon.jianbao.util.UILUtils;
import com.nostra13.universalimageloader.core.ImageLoader;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by keon on 2015/9/9.
 */
public class CommentListAdapter extends SimpleAdapter {
    static class ViewHolder {
        @Bind(R.id.comment_avatar)
        CircleImageView sdvAvatar;
        @Bind(R.id.comment_name)
        TextView tvName;
        @Bind(R.id.comment_time)
        TextView tvTime;
        @Bind(R.id.comment_content)
        TextView tvContent;

        public ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }

    @Override
    protected View getRealView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh = null;
        if (convertView == null || convertView.getTag() == null) {
            convertView = getLayoutInflater(parent.getContext()).inflate(
                    R.layout.list_cell_comment, null);
            vh = new ViewHolder(convertView);
            convertView.setTag(vh);
        } else {
            vh = (ViewHolder) convertView.getTag();
        }

        Comment comment = (Comment) mDatas.get(position);

        ImageLoader.getInstance().displayImage(comment.getUser_face(), vh.sdvAvatar, UILUtils.getOptions1());
//        vh.sdvAvatar.setImageURI(Uri.parse(comment.getUser_face()));
        vh.tvName.setText(comment.getUser_name());
        vh.tvTime.setText(comment.getCreate_time());
        vh.tvContent.setText(comment.getContent());

        return convertView;
    }
}
